package com.ksc.wordcount.task.map;

import com.ksc.wordcount.datasourceapi.PartionFile;
import com.ksc.wordcount.datasourceapi.PartionReader;
import com.ksc.wordcount.task.TaskContext;

import java.io.Serializable;

// Map任务上下文，继承自通用任务上下文类TaskContext
public class MapTaskContext extends TaskContext implements Serializable {

    PartionFile partiongFile; // 分区文件对象
    PartionReader partionReader; // 分区读取器对象
    int reduceTaskNum; // Reduce任务数量
    MapFunction mapFunction; // Map函数对象

    // 构造函数，用于初始化MapTaskContext对象
    public MapTaskContext(String applicationId, String stageId, int taskId, int partionId, PartionFile partiongFile, PartionReader partionReader, int reduceTaskNum, MapFunction mapFunction) {
        super(applicationId, stageId, taskId, partionId); // 调用父类的构造函数进行初始化
        this.partiongFile = partiongFile; // 初始化分区文件对象
        this.partionReader = partionReader; // 初始化分区读取器对象
        this.reduceTaskNum = reduceTaskNum; // 初始化Reduce任务数量
        this.mapFunction = mapFunction; // 初始化Map函数对象
    }

    // 获取分区文件对象
    public PartionFile getPartiongFile() {
        return partiongFile;
    }

    // 获取分区读取器对象
    public PartionReader getPartionReader() {
        return partionReader;
    }

    // 获取Reduce任务数量
    public int getReduceTaskNum() {
        return reduceTaskNum;
    }

    // 获取Map函数对象
    // 包含了url和1的键值对
    public MapFunction getMapFunction() {
        return mapFunction;
    }

}
